/****************************************************************************/
/*This program produces figure 4 using conventional event study figures     */
/****************************************************************************/
#delimit;
capture log close;

local pathsmr  C:\Research;
local Torpath  `pathsmr'\Tornadoes\0515Miles_CountyM;

/****************************************************************************/
/*Produce Point Estimates and CIs                                           */
/****************************************************************************/

local depvar "firm emp sales";

use `Torpath'\Temp\temp_program_5_alltreat_reg_analysis.dta, clear;

drop ysm4 ysm3 ysm2 ysm1 ysp0 ysp1 ysp2 ysp3 ysp4 ysp5 ;

forvalues i=0(1)10{;
	gen ydate_m`i'=ydate-`i';
	gen ydate_p`i'=ydate+`i';
	gen ysm`i'=(year==ydate_m`i');
	gen ysp`i'=(year==ydate_p`i');
	};

replace weighted_intensity = 0 if weighted_intensity==.;
gen after_weighted_intensity = after*weighted_intensity;
gen after_tint = after*weighted_intensity;

gen ysm4_t =  (ysm4*weighted_intensity);
gen ysm3_t =  (ysm3*weighted_intensity);
gen ysm2_t =  (ysm2*weighted_intensity);
gen ysm1_t =  (ysm1*weighted_intensity);
gen ysp0_t =  (ysp0*weighted_intensity);
gen ysp1_t =  (ysp1*weighted_intensity);
gen ysp2_t =  (ysp2*weighted_intensity);
gen ysp3_t =  (ysp3*weighted_intensity);
gen ysp4_t =  (ysp4*weighted_intensity);

foreach j of local depvar{;							

/*drop ysm1_t so its the comparision group*/
areg ln_`j'_all ysm4_t ysm3_t ysm2_t ysp0_t ysp1_t ysp2_t ysp3_t ysp4_t ysm4 ysm3 ysm2 ysm1 ysp0 ysp1 ysp2 ysp3 ysp4 weighted_intensity yeardum*,  vce (cluster tornado_id) absorb(bgfips); 
		  
};

save `Torpath'\Temp\temp.dta, replace;

/****************************************************************************/
/*Produce Event Study Figures                                               */
/****************************************************************************/

#delimit ;
local var1 "ln_firm_all ln_emp_all ln_sales_all";
#delimit cr

use "`Torpath'\dd_figures.dta", clear

drop if t ==4

	foreach var of local var1 {
	  if "`var'" == "ln_firm_all" {
		local title "Panel A"
		local ytitle "Growth of Establishments"
		local xtitle "Years Since Tornado"
	    }
	  else if "`var'" == "ln_emp_all" {
		local title "Panel B"
		local ytitle "Growth of Employment"
		local xtitle "Years Since Tornado"
	    }
	  else if "`var'" == "ln_sales_all" {
		local title "Panel C"
		local ytitle "Growth of Sales"
		local xtitle "Years Since Tornado"
	    }

	display "`var'"
	  twoway (sc `var'coef t, msymbol(S) msize(small) mcolor(blue) lcolor(blue) connect(none)) ///
			(rcap ci_h_`var' ci_l_`var' t, sort lpattern(solid) lcolor(blue))  ///
			,legend(off) ylabel(, labsize(vsmall)) ///
			title(`title', size(small)) ytitle("{bf:`ytitle'}", size(small)) xtitle("{bf: `xtitle'}", size(small)) /// 
			xline(-0.5,lpattern(solid) lcolor(maroon%80)) xmtick(-4 -3 -2 -1 0 1 2 3) xlabel(-4 -3 -2 -1 0 "1" 1 "2" 2 "3" 3 "4" , norescale)   yline(0,lpattern(dash) lcolor(gray)) ///
			scheme(s2mono) plotregion(fcolor(white)) graphregion(fcolor(white)) saving(`var'_YRS, replace)
	}
	

/****************************************************************************/
/*Create Figures for Paper                                                  */
/****************************************************************************/	


#delimit ;
	gr combine ln_firm_all_YRS.gph	
		   ln_firm_all_YRS.gph 
		   ln_firm_all_YRS.gph 
				   , 
				   col(3) scheme(s1mono) xsize(16) ysize(4);
				   graph display, scheme(s1mono);
				   graph export "Figures\BusinessEventS\DDpooled.pdf", as(pdf) replace;
		// Above 3x1 fig is for Firms, Employees and Sales
#delimit cr	
	

	